[FC-0099] refactor: manage enforcer state and casbin models only when app is ready#93
Conversation
|
Thanks for the pull request, @mariajgrimaldi! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
| if cls._enforcer is None: | ||
| cls._enforcer = cls._initialize_enforcer() |
There was a problem hiding this comment.
I don't think this would be needed.
6fedcea to
bcae860
Compare
This reverts commit 688bb9f.
…s while initializing application
d875701 to
5996ef9
Compare
BryanttV
left a comment
There was a problem hiding this comment.
@mariajgrimaldi, thanks for this! I was testing the REST API with these changes, and all works fine except for the permission validation.
I also built the openedx image, and it completed successfully 🚀
Description
This PR fixes an issue with including the library in non-testing environments since the Casbin adapter was trying to access the database when the apps were not fully loaded, raising errors like:
Now the initialization of the enforcer happens once when it's first used when the application is fully loaded. See https://github.com/officialpycasbin/django-orm-adapter/blob/5196741aadf6060023e933abedaac93e50008cc6/casbin_adapter/enforcer.py#L63-L79 for more details on what the initialization entails.